package infra.adapter.userDAO;

import infra.dao.user.UserDAO;
import java.io.IOException;
import java.util.LinkedList;
import models.User;

public class UserDAOAdapter {
    private UserDAO newUser;
    
    public UserDAOAdapter() {
        try {
            newUser = UserDAO.getInstance();
        } catch (IOException ex) {
            System.err.println("[Error] On UserDAOAdapter.constructor:");
            System.err.println("Could not get singleton instance.");
        }
    }

    public void createUser(User user) {
        if (newUser.ipUserExists(user.getIp()) || newUser.loginUserExists(user.getLogin())) {
            // get out of the method with some message.
        } else {
            newUser.createUser(user);
        }
    }
    
    public User retrieveUserByIp(String ip) {
        return newUser.retrieveUserByIp(ip);
    }
    public User retrieveUserByLogin(String login) {
        return newUser.retrieveUserByLogin(login);
    }

    public void updateUserByIp(String ip, User updatedUser) {
        newUser.updateUserByIp(ip, updatedUser);
    }
    public void updateUserByLogin(String login, User updatedUser) {
        newUser.updateUserByLogin(login, updatedUser);
    }
    
    public void deleteUserByIp(String ip) {
        newUser.deleteUserByIp(ip);
    }
    public void deleteUserByLogin(String login) {
        newUser.deleteUserByLogin(login);
    }
    
    public boolean ipUserExists(String ip) {
        return newUser.ipUserExists(ip);
    }
    public boolean loginUserExists(String login) {
        return newUser.loginUserExists(login);
    }
    
    public LinkedList<User> getAll() {
        return newUser.getAll();
    } 
}
